/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassFrame;

import GamePlay.CanvasGame;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author QuyetNM1
 */
public class Button extends FormItem {

    private static CFont Font = null;

    public Button(String stringName, int imageButton, int x, int y) {
        super(stringName, imageButton, x, y);
        Font = new CFont("/font/f_black.png",
                new byte[]{
                    7, 6, 7, 7, 7, 7, 7, 7, 7, 7,
                    4, 4, 4, 4, 8, 6, 6, 6, 5, 0, 8, 8, 8, 8, //.,:!?()+*|>/-%
                    7, 8, 6, 8, 7, 5, 8, 8, 4, 6,//abcdefghij
                    7, 4, 10, 8, 7, 7, 7, 6, 6, 5,//klmnopqrst
                    7, 7, 10, 7, 8, 6, 7, 7, 7, 7,//uvwxyzáàảã
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,//ạăắằẳẵặâấầ
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,//ẩẫậéèẻẽẹêế
                    8, 8, 8, 8, 5, 5, 5, 5, 5, 8,//ềểễệíìỉĩịóò
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
                    7, 7, 7,
                    8, 8, 8, 8, 6, 6, 8, 8, 4, 6, //ABCDEFGHIJ
                    7, 6, 11, 9, 8, 8, 8, 8, 8, 7,//KLMNOPQRST
                    8, 8, 11, 8, 8, 7, 8, 8, 8,//UVWXYZĐ$Ă
                },
                13, 3, "0123456789.,:!?()+*|>/-%abcdefghijklmnopqrstuvwxyzáàảãạăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđABCDEFGHIJKLMNOPQRSTUVWXYZĐ$Ă");
    }

    public Button(CanvasGame canvas, String stringName, int image1, int x, int y, int w, int h) {
        super(canvas, stringName, image1, x, y, w, h);
    }

    public void drawButton(Graphics g, CanvasGame canvas) {
        if(state == DISABLE) return;
        canvas.getImage().drawImagePart(g, canvas, image1, x, y, 0, state * h, w, h);
        Font.Render(g, stringName, x + w / 2, y + h / 4, CFont.ALIGN_CENTER);
    }

    public void drawButton(Graphics g) {
        canvas.getImage().drawImagePart(g, canvas, image1, x, y, 0, state * h, w, h);
    }

    public boolean isClick(int x, int y) {
        if (state == DISABLE) {
            return false;
        }
        if (x <= this.x || x >= this.x + w) {
            return false;
        } else if (y <= this.y || y >= this.y + h) {
            return false;
        }
        return true;
    }
}
